﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using System.Data.SqlClient;
using DevExpress.XtraGrid.Views.Grid;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Lab_NoteBook : frmBaseChild
    {
        public frmMES_Lab_NoteBook()
        {
            InitializeComponent();
        }
        //RGB常用对照表
        //https://tool.oschina.net/commons?type=3

        //DevExpress GridControl 关于使用CardView的一点小结
        //https://blog.csdn.net/yang472024191/article/details/40536327?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //【Devexpress】GridControl之CardView
        //https://blog.csdn.net/XChicken/article/details/16896181?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //在DevExpress GridControl的一列中显示图片
        //https://blog.csdn.net/weixin_34038293/article/details/90616561?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //DevExpress ChartControl 多数据时滚动条处理
        //https://blog.csdn.net/zhoen889/article/details/17301405?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //Dev中ChartControl添加限定线
        //https://blog.csdn.net/Tiger_shl/article/details/82385692?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //用Dev的ChartControl绘制圆滑曲线并插到excel中！
        //https://blog.csdn.net/qq_29093033/article/details/89349219

        //DEVEXPRESS GRIDVIEW 自定义实现底部汇总
        //https://www.cnblogs.com/qq-xiao/p/6121358.html

        //DevExpress 控件使用笔记 - Common Controls
        //https://blog.csdn.net/weixin_33714884/article/details/92548634

        //DevExpress GridView 单元格进度条的绑定及拓展自定义进度条不同颜色显示
        //https://blog.csdn.net/cxu123321/article/details/93351648

        //“步步精心”——三层架构下GridView控件实现增删改查
        //https://blog.csdn.net/iteye_3224/article/details/82373073?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task


        //const string SchedulerDBConnection = @"data source=172.23.134.36;initial catalog=LamexMESManager;user id=sa;password=Sa@1050%";

        ////缓存表插入数据库
        //string delete_sql = @"delete from NC_PN_AL_TEMP001 where FILE_NAME='" + dt_Result.Rows[0]["FILE_NAME"].ToString() + "' ";
        //BaseBuildSql.ExecuteNonQuery(delete_sql);
        //if (BaseBuildSql.ExcuteInsert(dt_Result, "NC_PN_AL_TEMP001"))
        //{
        //}

        //将 datatable 数据导入到 SQL Server
        //DataTable中的列需要与数据库表中的列完全一致。
        //数据增删改操作见【frmLBR_LaborTime_Maintain】

        //using (WaitDialogForm wdf = new WaitDialogForm("请稍侯", "数据分析中......", new Size(400, 80)))
        //{
        //}



        private void frmMES_Lab_NoteBook_Load(object sender, EventArgs e)
        {
            //DevExpress gridView常用属性和技巧介绍
            //https://www.cnblogs.com/yimeishui/articles/5737511.html

            #region 两种调用数据库方法
            string conStr = @"data source=172.23.134.36;initial catalog=LamexMESManager;user id=sa;password=Sa@1050%";
            //string conStr = SqlConfiguration.CurrentConnectionString;

            string strSql = @"SELECT WORKER_NO,WORKER_NAME,PHOTO FROM HR_Workers_Info";
            //DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);

            SqlConnection cnn = new SqlConnection(conStr);
            SqlCommand cmd = new SqlCommand(strSql, cnn);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            adp.Fill(dt);

            gridControl1.DataSource = dt;

            #endregion

            //GridView加载数据，演示用，加到Load事件中
            //List<object> list = new List<object>();
            //list.Add(new { BgColor = 11, BgColor2 = 12, FontColor = 13 });
            //list.Add(new { BgColor = 21, BgColor2 = 22, FontColor = 23 });
            //list.Add(new { BgColor = 31, BgColor2 = 32, FontColor = 33 });
            //gridControl1.DataSource = list;

            //遍历GridView每行
            for (int i = 1; i < gridView1.RowCount; i++)
            {
                for (int j = 0; j < gridView1.Columns.Count; j++)
                {
                    //string str = gridView1.GetRowCellDisplayText(i, "DRAWING_NO_STANDARD").ToString()；
                    //str = gridView1.GetRowCellValue(0, gridView1.Columns[0]);
                    //str = gridView1.GetRowCellValue(0, gridView1.Columns[j]];
                    //gridView1.CELLS
                    //gridView1.rows[4].cells[3].backcolor = Color.Red;
                }
            }

            //遍历GridView每列
            for (int i = 0; i < gridView1.Columns.Count; i++)
            {
                //gridView1.BestFitColumns();
                //gridView1.Columns[i].BestFit();//自动列宽
                gridView1.Columns[i].AppearanceCell.BackColor= Color.White;
            }
        }

        //GridView设置列格式
        private void gridView1_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            GridView View = sender as GridView;
            //if (e.Column.FieldName == "BgColor")//设背景
            //{
            //    //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
            //    e.Appearance.BackColor = Color.Red;
            //}
            //else if (e.Column.FieldName == "BgColor2")//设渐变背景
            //{
            //    //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
            //    e.Appearance.BackColor = Color.Red;
            //    e.Appearance.BackColor2 = Color.FromArgb(255, 255, 255);
            //}
            //else if (e.Column.FieldName == "FontColor")//设字体颜色
            //{
            //    //int pointID = (gridView1.GetRow(e.RowHandle) as object).BgColor;
            //    e.Appearance.ForeColor = Color.Red;//Color.FromArgb(42, 173, 231);
            //}
        }

        ////更改gridcontrol控件cardview的cardCaption标题
        //private void cardView1_CustomDrawCardCaption(object sender, DevExpress.XtraGrid.Views.Card.CardCaptionCustomDrawEventArgs e)
        //{
        //    CardView view = sender as DevExpress.XtraGrid.Views.Card.CardView;
        //    (e.CardInfo as CardInfo).CaptionInfo.CardCaption = view.GetRowCellDisplayText(e.RowHandle, view.Columns[0]);
        //}
    }
}